const express = require('express');
const asyncHandler = require('express-async-handler');
const router = express.Router();
module.exports = router;

router.get('/getPersonnelSummary', asyncHandler(getPersonnelSummary));
router.get('/getSitePersonnelRecord', asyncHandler(getSitePersonnelRecordGet))
router.post('/getSitePersonnelRecord', asyncHandler(getSitePersonnelRecordPost))


async function getSitePersonnelRecordGet(req, res) {
    let result = [{
        "_id": "ba14357f3ad1",
        "workerName": "王瑞",
        "gender": "male",
        "age": 47,
        "workerType": "架子工",
        "temperature": "37.2",
        "phone": "156*****150",
        "type": "in",
        "time": "2023-03-10T08:00:00Z"
    },
    {
        "_id": "ba14357f3ad2",
        "workerName": "肖河港",
        "gender": "male",
        "age": 27,
        "workerType": "钢筋工",
        "temperature": "36.2",
        "phone": "138*****230",
        "type": "in",
        "time": "2023-03-10T09:00:00Z"
    },
    {
        "_id": "ba14357f3ad3",
        "workerName": "李易航",
        "gender": "male",
        "age": 39,
        "workerType": "瓦工",
        "temperature": "37.1",
        "phone": "189*****423",
        "type": "in",
        "time": "2023-03-10T10:00:00Z"

    },
    {
        "_id": "ba14357f3ad4",
        "workerName": "于凤源",
        "gender": "male",
        "age": 21,
        "workerType": "塔吊班组",
        "temperature": "36.3",
        "phone": "139*****450",
        "type": "in",
        "time": "2023-03-10T10:12:00Z"
    },
    {
        "_id": "ba14357f3ad5",
        "workerName": "李铁",
        "gender": "male",
        "age": 57,
        "workerType": "架子工",
        "temperature": "37.3",
        "phone": "156*****389",
        "type": "out",
        "time": "2023-03-10T11:00:00Z"
    },
    {
        "_id": "ba14357f3ad6",
        "workerName": "刘大猛",
        "gender": "male",
        "age": 32,
        "workerType": "模板工",
        "temperature": "36.2",
        "phone": "191*****251",
        "type": "out",
        "time": "2023-03-10T11:47:00Z"
    },
    {
        "_id": "ba14357f3ad7",
        "workerName": "王德发",
        "gender": "male",
        "age": 41,
        "workerType": "管理班组",
        "temperature": "36.9",
        "phone": "180*****475",
        "type": "in",
        "time": "2023-03-10T12:25:00Z"
    }]
    res.json(result)
}

async function getSitePersonnelRecordPost(req, res) {
    let result = {
        "_id": "ba14357f3ad1",
        "workerName": "王瑞",
        "gender": "male",
        "age": 47,
        "workerType": "架子工",
        "temperature": "37.2",
        "phone": "156*****150",
        "dateOfBirth": "1974-08-01T08:00:00Z", //出生日期
        "nationality": "汉", //民族
        "group": "XXXXXXXXX", //参建单位
        "contractStartDate": "2023-01-10T08:00:00Z", //用工日期
        "contractEndDate": "2023-07-10T08:00:00Z", //结束日期
        "studyStatus": "已完成", //培训状态
        "identityNumber": "4103**********0315" //证件号码
    }
    res.json(result)
}

async function getPersonnelSummary(req, res) {
    res.json(
        {
            "dailySiteliveOverview": {
                "totalPplCount": 23, //当前在场人数
                "sitePplCount": 46 //今日出勤人数
            },
            "dailySiteInOutOverview": [
                {
                    "inOutTime": 1,//进场1次
                    "pplCount": 9 //人数
                },
                {
                    "inOutTime": 2,//进场2次
                    "pplCount": 14
                },
                {
                    "inOutTime": 3,//进场2次以上
                    "pplCount": 7
                }
            ],

            "dailyTeamOverview": [
                {
                    "wokerType": "木工",//工种
                    "pplCount": 9 //人数
                },
                {
                    "wokerType": "钢筋工",
                    "pplCount": 3
                },
                {
                    "wokerType": "模板工",
                    "pplCount": 5
                },
                {
                    "wokerType": "架子工",
                    "pplCount": 4
                },
                {
                    "wokerType": "塔吊班组",
                    "pplCount": 7
                },
                {
                    "wokerType": "管理班组",
                    "pplCount": 2
                },
                {
                    "wokerType": "瓦工",
                    "pplCount": 7
                }
            ],
            "trendOfInOut": [
                {
                    "timePeriod": 8, //时间段 8standsfor 8：00～9:00
                    "pplIn": 5,
                    "pplOut": 7
                },
                {
                    "timePeriod": 9,
                    "pplIn": 4,
                    "pplOut": 2
                },
                {
                    "timePeriod": 10,
                    "pplIn": 5,
                    "pplOut": 4
                },
                {
                    "timePeriod": 11,
                    "pplIn": 9,
                    "pplOut": 7
                },
                {
                    "timePeriod": 12,
                    "pplIn": 6,
                    "pplOut": 9
                },
                {
                    "timePeriod": 13,
                    "pplIn": 2,
                    "pplOut": 8
                },
                {
                    "timePeriod": 14,
                    "pplIn": 3,
                    "pplOut": 1
                },
                {
                    "timePeriod": 15,
                    "pplIn": 7,
                    "pplOut": 2
                },
                {
                    "timePeriod": 16,
                    "pplIn": 11,
                    "pplOut": 7
                },
                {
                    "timePeriod": 17,
                    "pplIn": 15,
                    "pplOut": 5
                },
                {
                    "timePeriod": 18,
                    "pplIn": 3,
                    "pplOut": 17
                }
            ]
        })
}